﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharpMUD.Framework.Workflow.Generic
{
    public interface IExecutionStatusToken
    {
        string Name { get; }
    }
    public interface IExecutionStatusTransitionToken
    {
        IExecutionStatusToken Previous { get; }
        IExecutionStatusToken Next { get; }
    }
    internal class ExecutionStatusToken
        : IExecutionStatusToken
    {
        private ExecutionStatusToken() {}
        protected internal ExecutionStatusToken(string name)
        {
            if (String.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

            this.Name = name;
        }

        #region IExecutionStatusToken Members

        public string Name
        {
            get; private set;
        }

        #endregion

        public override string ToString()
        {
            return  "{" + this.Name + "}";
        }
    }
    internal class ExecutionStatusTransitionToken
        : ExecutionStatusToken, IExecutionStatusTransitionToken
    {

        internal ExecutionStatusTransitionToken(string name, IExecutionStatusToken previous, IExecutionStatusToken next)
            :base(name)
        {
            if (previous == null) throw new ArgumentNullException("previous");
            if (next == null) throw new ArgumentNullException("next");

            this.Previous = previous;
            this.Next = next;
        }

        #region IExecutionStatusTransitionToken Members

        public IExecutionStatusToken Previous
        {
            get;
            private set;
        }

        public IExecutionStatusToken Next
        {
            get;
            private set;
        }

        #endregion
    }

    public static class ExecutionStatusTokens
    {
        public static readonly IExecutionStatusToken UnInitialized = new ExecutionStatusToken("UnInitialized");
        public static readonly IExecutionStatusToken Initialized = new ExecutionStatusToken("Initialized");
        public static readonly IExecutionStatusToken Initializing = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Initializing", UnInitialized, Initialized);

        public static readonly IExecutionStatusToken Running = new ExecutionStatusToken("Running");
        public static readonly IExecutionStatusToken Starting = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Starting", Initialized, Running);

        public static readonly IExecutionStatusToken Suspended = new ExecutionStatusToken("Suspended");
        public static readonly IExecutionStatusToken Suspending = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Suspending", Running, Suspended);
        public static readonly IExecutionStatusToken Resuming = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Resuming", Suspended, Running);

        public static readonly IExecutionStatusToken Stopped = new ExecutionStatusToken("Stopped");
        public static readonly IExecutionStatusToken Stopping = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Stopping", Running, Stopped);

        public static readonly IExecutionStatusToken Disposed = new ExecutionStatusToken("Disposed");
        public static readonly IExecutionStatusToken Disposing = (IExecutionStatusToken)new ExecutionStatusTransitionToken("Disposing", Initialized, Disposed);

    }
    
}
